package com.zzkj.util
{
	import com.firemoss.modelglue.event.ModelGlueEvent;
	import com.storage.model.AppModelLocator;
	import com.storage.vo.system.UnitVO;
	import com.zzkj.vo.query.QueryInfoVO;
	
	public class ReloadUtil
	{
		public function ReloadUtil()
		{
		}
		private static var entity:String;
		private static var q:QueryInfoVO;
		private static var e:ModelGlueEvent;
		
		private static var model:AppModelLocator = AppModelLocator.getInstance();
		
		//集团公司操控的
		public static function reloadUnit(ifWaiSi:String=null,system:Boolean=false):void{
			
			
			
			entity = "com.storage.system.entity.Unit";
			if(ifWaiSi!=null)
				q = QueryBuilder.createQuery(entity,[{name:"ifWaiSi",value:ifWaiSi,
						condition:QueryInfoVO.CONDITION_EQ}]);
			else if(!system)
				q = QueryBuilder.createQuery(entity,
							[{name:'shortName',value:'system'
							,condition:QueryInfoVO.CONDITION_NEQ}]);
			else if(system)
				q = QueryBuilder.createQuery(entity,null);
				
			e = new ModelGlueEvent("doCommonSearch");
			e.setValue('name','unit');
			e.setValue("query",q);
			e.dispatch();
		}
		//集团公司操控的
		public static function reloadDepartment():void{
			
			entity = "com.storage.system.entity.Department";
			q = QueryBuilder.createQuery(entity,null);
			e = new ModelGlueEvent("doCommonSearch");
			e.setValue('name','department');
			e.setValue("query",q);
			e.dispatch();
		}
		//集团公司操控的
		public static function reloadPermission():void{
			
			entity = "com.storage.system.entity.Permission";
			q = QueryBuilder.createQuery(entity,null);
			e = new ModelGlueEvent("doCommonSearch");
			e.setValue('name','permission');
			e.setValue("query",q);
			e.dispatch();
		}
		
		//需要跟单位unitNo
		public static function reloadRole(unit:UnitVO=null):void{
			
			entity = "com.storage.system.entity.Role";
			//如果不为空，则根据Unit去查询
			if(unit!= null)
				q = QueryBuilder.createQuery(entity,[{name:'unit',value:unit
							,condition:QueryInfoVO.CONDITION_EQ}]);
			//如果为空，且当前用户是超管
			else if(model.currentUser.role.roleName=="SuperAdminHidden")
				q = QueryBuilder.createQuery(entity,null);
			//如果为空，不是当前超管
			else
				q = QueryBuilder.createQuery(entity,
						[{name:'roleName',value:'SuperAdminHidden'
							,condition:QueryInfoVO.CONDITION_NEQ}]);
			e = new ModelGlueEvent("doCommonSearch");
			e.setValue('name','role');
			e.setValue("query",q);
			e.dispatch();
		}
		//需要跟单位unitNo
		public static function reloadChildModule(menuName:String,unit:UnitVO=null):void{
			
			entity = "com.storage.system.entity.ChildModule";
			if(unit!=null)
				q = QueryBuilder.createQuery(entity,[{name:'unit',value:unit
						,condition:QueryInfoVO.CONDITION_EQ}
						,{name:'menuName',value:menuName
							,condition:QueryInfoVO.CONDITION_EQ}]);
			else
				q = QueryBuilder.createQuery(entity,[{name:'menuName',value:menuName
							,condition:QueryInfoVO.CONDITION_EQ}]);
			e = new ModelGlueEvent("doCommonSearch");
			e.setValue('name','childModule');
			e.setValue("query",q);
			e.dispatch();
		}
		//需要跟单位unitNo
		public static function reloadModule(menuName:String,unit:UnitVO=null):void{
			
			entity = "com.storage.system.entity.Module";
			if(unit!=null)
				q = QueryBuilder.createQuery(entity,[{name:'unit',value:unit
						,condition:QueryInfoVO.CONDITION_EQ}
						,{name:'menuName',value:menuName
							,condition:QueryInfoVO.CONDITION_EQ}]);
			else
				q = QueryBuilder.createQuery(entity,[{name:'menuName',value:menuName
							,condition:QueryInfoVO.CONDITION_EQ}]);
			e = new ModelGlueEvent("doCommonSearch");
			e.setValue('name','module');
			e.setValue("query",q);
			e.dispatch();
		}
		//车站
		public static function reloadStation():void{
			
			entity = "com.storage.system.entity.Station";
			q = QueryBuilder.createQuery(entity,null);
			e = new ModelGlueEvent("doCommonSearch");
			e.setValue('name','station');
			e.setValue("query",q);
			e.dispatch();
		}
		//车类型
		/* public static function reloadBusType():void{
			
			entity = "com.storage.system.entity.BusType";
			q = QueryBuilder.createQuery(entity,null);
			e = new ModelGlueEvent("doCommonSearch");
			e.setValue('name','busType');
			e.setValue("query",q);
			e.dispatch();
		} */
		
		
		
	}
}